package gang.org.springframework.framework.annotation;

import gang.org.springframework.framework.bean.GangBeanDefinitionHolder;
import gang.org.springframework.framework.io.GangResourceLoader;
import gang.org.springframework.framework.metadata.GangAnnotationAttributes;
import gang.org.springframework.framework.support.GangBeanDefinitionRegistry;
import gang.org.springframework.framework.support.GangBeanNameGenerator;
import gang.org.springframework.framework.util.GangStringUtils;

import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;

/**
 * @author gang.chen
 * @Date 2022/9/21 8:46
 */
public class GangComponentScanAnnotationParser {

    private final Object enviroment;

    private final GangResourceLoader resourceLoader;

    private final GangBeanNameGenerator  beanNameGenerator;

    private final GangBeanDefinitionRegistry registry;

    public GangComponentScanAnnotationParser(Object enviroment, GangResourceLoader resourceLoader, GangBeanNameGenerator beanNameGenerator, GangBeanDefinitionRegistry registry) {
        this.enviroment = enviroment;
        this.resourceLoader = resourceLoader;
        this.beanNameGenerator = beanNameGenerator;
        this.registry = registry;
    }

    public Set<GangBeanDefinitionHolder> parse(GangAnnotationAttributes componentScan, String declaringClass){
        GangClassPathBeanDefinitionScanner scanner = new GangClassPathBeanDefinitionScanner(this.registry, componentScan.getBoolean("useDefaultFilters"), this.enviroment, this.resourceLoader);

        //nameGenerator
        scanner.setBeanNameGenerator(this.beanNameGenerator);

        //scopedProxy


        //scopeResolver


        //resourcePattern


        //includeFilters


        //excludeFilters


        //lazyInit


        //basePackages
        Set<String> basePackages = new LinkedHashSet<>();
        String[] basePackagesArray = componentScan.getStringArray("basePackages");
        Collections.addAll(basePackages, basePackagesArray);

        //basePackageClasses

        return scanner.doScan(GangStringUtils.toStringArray(basePackages));
    }
}
